//封装分类 图业务逻辑代码

import { getCategoryAPI } from "@/apis/category.js";
import { onMounted, ref } from "vue";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
export const useCategory = () => {
    //获取面包屑数据
    const route = useRoute();
    const categoryData = ref([]);
    const getCategory = async (id = route.params.id) => {
        const res = await getCategoryAPI(id);
        categoryData.value = res.result;
    };
    //组件内路由导航守卫
    onBeforeRouteUpdate((to) => {
        getCategory(to.params.id);
    });
    onMounted(() => getCategory());
    return { categoryData }
}